import { ButtonGroup, Button } from "@douyinfe/semi-ui";
import { Popconfirm, Table, message } from "antd";

import useInstitutionDeletePosition from "../../hooks/institution/useDeletePosition";

const InstitutionPositions = ({ loading, positions, reloadData }) => {
    const { deleteInstitutionPosition } = useInstitutionDeletePosition();

    const renderOperate = (_, r, i) => (
        <ButtonGroup>
            <Popconfirm
                title="确认要删除该岗位信息吗？"
                okButtonProps={{ loading: false }}
                onConfirm={async () => {
                    let res = await deleteInstitutionPosition(r.reUuid);
                    if (res) {
                        message.success("成功移除岗位信息");
                        reloadData();
                    }
                }}
            >
                <Button theme="borderless" style={{ color: "#f50" }}>
                    移除
                </Button>
            </Popconfirm>
        </ButtonGroup>
    );

    return (
        <Table loading={loading} bordered dataSource={positions} rowKey={"id"} size="small" pagination={false}>
            <Table.Column title="序号" width={60} align="center" render={(_, r, i) => i + 1} />
            <Table.Column title="姓名" dataIndex={"osName"} />
            <Table.Column title="岗位" dataIndex={"opName"} width={140} />
            <Table.Column title="操作" width={80} render={renderOperate} />
        </Table>
    );
};

export default InstitutionPositions;
